#!/bin/bash

if [[ ${UID} -ne 0 ]];then
	echo "this script must be run as root!"
	exit 1
fi

if ! mountpoint -q /mnt; then
    mount /dev/mmcblk0p1 /mnt/
    if [[ -f /mnt/BOOT.bin ]];then
	mv /mnt/BOOT.bin /mnt/BOOT.bin.bak
    else
        echo "Error:There is no BOOT.bin in /mnt!"
	exit 1
    fi

    if [ ! $? ];then
        echo "Error:Mount faild!"
        exit 1
    fi
fi
if [[ -f BOOT.bin ]];then
    cp BOOT.bin /mnt/
else
    echo "Error:There is no BOOT.bin in current directory!"
    exit 1
fi

if [[ $? ]];then
    echo "BOOT.bin copy to /mnt successfully!"
fi
umount /mnt
